﻿namespace OboutInc.EasyMenu_Pro
{
    using System;
    using System.ComponentModel;
    using System.Drawing.Design;
    using System.Web.UI.Design;
    using System.Xml;

    [Serializable, ToolboxItem(false)]
    public class MenuItem : ItemBase
    {
        public MenuItem()
        {
        }

        public MenuItem(string id) : this()
        {
            this.ID = id;
        }

        public MenuItem(string id, string InnerHtml) : this(id)
        {
            this.InnerHtml = InnerHtml;
        }

        public MenuItem(string id, string InnerHtml, string Icon) : this(id, InnerHtml)
        {
            this.Icon = Icon;
        }

        public MenuItem(string id, string InnerHtml, string Icon, string Url) : this(id, InnerHtml, Icon)
        {
            this.Url = Url;
        }

        public MenuItem(string id, string InnerHtml, string Icon, string Url, string UrlTarget) : this(id, InnerHtml, Icon, Url)
        {
            this.UrlTarget = UrlTarget;
        }

        public MenuItem(string id, string InnerHtml, string Icon, string Url, string UrlTarget, string OnClientClick) : this(id, InnerHtml, Icon, Url, UrlTarget)
        {
            this.OnClientClick = OnClientClick;
        }

        public MenuItem(string id, string InnerHtml, string Icon, string Url, string UrlTarget, string OnClientClick, bool AllowsIcon) : this(id, InnerHtml, Icon, Url, UrlTarget, OnClientClick)
        {
            this.AllowsIcon = AllowsIcon;
        }

        public override void Deserialize(XmlElement parentNode)
        {
            this.ID = parentNode.GetAttribute("ID");
            this.InnerHtml = parentNode.GetAttribute("InnerHtml");
            this.Icon = parentNode.GetAttribute("Icon");
            this.Url = parentNode.GetAttribute("Url");
            this.UrlTarget = parentNode.GetAttribute("UrlTarget");
            this.OnClientClick = parentNode.GetAttribute("OnClientClick");
            this.AllowsIcon = bool.Parse(parentNode.GetAttribute("AllowsIcon"));
            this.AutoHideMenu = bool.Parse(parentNode.GetAttribute("AutoHideMenu"));
            this.ItemDescription = parentNode.GetAttribute("Description");
        }

        public override void Serialize(ref XmlElement parentNode)
        {
            parentNode.SetAttribute("ID", this.ID);
            parentNode.SetAttribute("InnerHtml", this.InnerHtml);
            parentNode.SetAttribute("Icon", this.Icon);
            parentNode.SetAttribute("Url", this.Url);
            parentNode.SetAttribute("UrlTarget", this.UrlTarget);
            parentNode.SetAttribute("OnClientClick", this.OnClientClick);
            parentNode.SetAttribute("AllowsIcon", this.AllowsIcon.ToString());
            parentNode.SetAttribute("AutoHideMenu", this.AutoHideMenu.ToString());
            parentNode.SetAttribute("Description", this.ItemDescription);
        }

        public override string AddonAttributes
        {
            get
            {
                return (((this.OnClientClick.Length > 0) ? ("OnClientClick:\"" + this.OnClientClick.Replace("'", "'") + "\",") : string.Empty) + (this.Disabled ? "disabled:\"disabled\"," : "") + ((this.ItemDescription.Length > 0) ? ("description:\"" + this.ItemDescription + "\",") : string.Empty));
            }
        }

        [Bindable(true), DefaultValue(true), Description("If this item allows an icon to be shown near it."), Category("Appearance")]
        public override bool AllowsIcon
        {
            get
            {
                object obj2 = this.ViewState["AllowsIcon"];
                if (obj2 != null)
                {
                    return (bool) obj2;
                }
                return true;
            }
            set
            {
                this.ViewState["AllowsIcon"] = value;
            }
        }

        [Category("Behavior"), DefaultValue(true), Description("If the menu should hide upon clicking this item or not."), Bindable(true)]
        public override bool AutoHideMenu
        {
            get
            {
                object obj2 = this.ViewState["AutoHideMenu"];
                if (obj2 != null)
                {
                    return (bool) obj2;
                }
                return true;
            }
            set
            {
                this.ViewState["AutoHideMenu"] = value;
            }
        }

        [NotifyParentProperty(true), DefaultValue(false), Bindable(true), Category("Behavior"), Description("If the item is disabled or not.")]
        public bool Disabled
        {
            get
            {
                object obj2 = this.ViewState["Disabled"];
                return ((obj2 != null) && ((bool) obj2));
            }
            set
            {
                this.ViewState["Disabled"] = value;
            }
        }

        internal bool HasSubmenu
        {
            get
            {
                object obj2 = this.ViewState["HasSubmenu"];
                return ((obj2 != null) && ((bool) obj2));
            }
            set
            {
                this.ViewState["HasSubmenu"] = value;
            }
        }

        [Description("Image to show near the MenuItem."), Bindable(true), Category("Appearance"), DefaultValue(""), Editor(typeof(UrlEditor), typeof(UITypeEditor))]
        public override string Icon
        {
            get
            {
                if (this.AllowsIcon)
                {
                    object obj2 = this.ViewState["Icon"];
                    if (obj2 != null)
                    {
                        return (string) obj2;
                    }
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["Icon"] = value;
            }
        }

        [DefaultValue(""), NotifyParentProperty(true), Description("Text or any client side code to display."), Bindable(true), Category("Behavior")]
        public override string InnerHtml
        {
            get
            {
                object obj2 = this.ViewState["InnerHTML"];
                if (obj2 != null)
                {
                    return (string) obj2;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["InnerHTML"] = value;
            }
        }

        [NotifyParentProperty(true), Bindable(true), Category("Behavior"), DefaultValue(""), Description("Text or any client side code to display.")]
        public string ItemDescription
        {
            get
            {
                object obj2 = this.ViewState["ItemDescription"];
                if (obj2 != null)
                {
                    return (string) obj2;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["ItemDescription"] = value;
            }
        }

        [Description("Client side code to run when user clicks."), Bindable(true), Category("Behavior"), DefaultValue("")]
        public string OnClientClick
        {
            get
            {
                object obj2 = this.ViewState["OnClientClick"];
                if (obj2 != null)
                {
                    return (string) obj2;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["OnClientClick"] = value;
            }
        }

        [Editor(typeof(UrlEditor), typeof(UITypeEditor)), Bindable(true), Category("Behavior"), DefaultValue(""), Description("URL to open when user clicks.")]
        public string Url
        {
            get
            {
                object obj2 = this.ViewState["Url"];
                if (obj2 != null)
                {
                    return (string) obj2;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["Url"] = value;
            }
        }

        [Bindable(true), Description("URL target frame name."), Category("Behavior"), DefaultValue("")]
        public string UrlTarget
        {
            get
            {
                object obj2 = this.ViewState["UrlTarget"];
                if (obj2 != null)
                {
                    return (string) obj2;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["UrlTarget"] = value;
            }
        }
    }
}

